package com.arron.algorithm.leetcodetop100.二叉树;

import com.arron.algorithm.tree.TreeNode;

public class 合并二叉树 {


    public TreeNode mergeTrees(TreeNode root1, TreeNode root2) {

        TreeNode root;
        if (root1 != null && root2!=null){
            root = new TreeNode(root1.val+root2.val);
        }else if (root1 ==null && root2 != null){
            root = root2;
            return root;
        }else if (root1 !=null && root2 == null){
            root = root1;
            return root;
        }else {
            return null;
        }
        root.left = mergeTrees(root1.left,root2.left);
        root.right = mergeTrees(root1.right,root2.right);
        return root;
    }


}
